package com.quxiu.system.api.factory;

import com.quxiu.common.core.domain.R;
import com.quxiu.system.api.RemoteIdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * ID服务降级处理
 *
 * @author quxiu
 */
@Component
public class RemoteIdFallbackFactory implements FallbackFactory<RemoteIdService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteIdFallbackFactory.class);

    @Override
    public RemoteIdService create(Throwable throwable) {
        log.error("ID服务调用失败:{}", throwable.getMessage());
        return new RemoteIdService() {
            @Override
            public R<Long> nextId(String source) {
                return R.fail("获取ID失败:" + throwable.getMessage());
            }
        };
    }
}
